package com.sanley.coronavirus.service.iml;

import com.github.pagehelper.PageHelper;
import com.sanley.coronavirus.dao.NotificationDao;
import com.sanley.coronavirus.dao.UserDao;
import com.sanley.coronavirus.entity.Notification;
import com.sanley.coronavirus.entity.User;
import com.sanley.coronavirus.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.List;

/**
 * @Author: ming
 * @create: 2022-11-16 13:40
 * @program: coronavirus
 */
@Service
public class NotificationServiceImpl implements NotificationService {

    @Autowired
    private NotificationDao notificationDao;

    @Autowired
    private UserDao userDao;

    @Override
    public List<Notification> queryNotification(int page, int size) {
        PageHelper.startPage(page, size);
        return notificationDao.queryNotification();
    }

    @Override
    public int addNotification(Notification notification, String username) {
        User user = userDao.findByUsername(username);

        notification.setUserId(user.getId());
        notification.setNotificationTime(new Date(System.currentTimeMillis()));
        notification.setIsDelete(false);
        return notificationDao.addNotification(notification);
    }

    @Override
    public int delete(Integer id) {
        return notificationDao.deleteNotificationById(id);
    }

    @Override
    public int updateNotification(Notification notification) {
        return notificationDao.updateNotificationById(notification);
    }

    @Override
    public Notification getNotificationById(int id) {

        return notificationDao.getNotificationById(id);
    }

    @Override
    public List<Notification> getNotificationByTittle(String tittle, int page, int size) {
        PageHelper.startPage(page, size);
        return notificationDao.getNotificationByTittle(tittle);
    }
}
